* Change the directory to the top one for this project
set more off
capture cd "C:\Users\Benjamin Allen\Loewen-RubensonLab Dropbox\LR Research Lab - Shared\Papers\Support for Algorithmic Governance"
capture cd "C:\Users\balle\Loewen-RubensonLab Dropbox\LR Research Lab - Shared\Papers\Support for Algorithmic Governance"
capture cd "~\Loewen-RubensonLab Dropbox\LR Research Lab - Shared\Papers\Support for Algorithmic Governance"

use "data/EPIS_data recoded and labeled with scales.dta", clear

********************************************************************************
* Hierarchical models
********************************************************************************

codebook alg_govt_acceptable_scale_bi
*hist alg_govt_acceptable_scale_bi

codebook 	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	leader_approval_rescaled

*------------------------------------------------------------------------------*
* loneway ANOVA
*------------------------------------------------------------------------------*	
	
loneway alg_govt_acceptable_scale_bi country_recoded

*------------------------------------------------------------------------------*
* Random Effects ANOVA
*------------------------------------------------------------------------------*	
	
mixed alg_govt_acceptable_scale_bi, || country_recoded:
	
* Expected proportion of reasons supported is 54.2% (the fixed effects intercept), with a 95% confidence interval of 51.7% to 56.8%
	
* Intra-class correlation
estat icc

* Okay, so when I do a really basic Random Effects ANOVA, we find that coutnry accounts for about 2% of the variance (1% to 4%)
* So, frankly, the country level doesn't matter a whole lot

*------------------------------------------------------------------------------*
* Replicating with a basic ANOVA
*------------------------------------------------------------------------------*	

* Testing assumption #6, homogeneity of variances, with Levene's test
robvar alg_govt_acceptable_scale_bi, by(country_recoded)

* There IS a statistically significant difference in the variance of acceptability between countries
* What does this mean for my ANOVA?
* Some different advice:
*		While that DOES imply that I should be cautious with interpreting the ANOVA: https://www.statology.org/levenes-test-stata/#:~:text=Levene's%20Test%20is%20used%20to,that%20groups%20have%20equal%20variances.
*		There is also advice that one-way ANOVA is robust to heterogeneity of variance WHEN the sample sizes are equal, which is true in this case: https://www.researchgate.net/post/What_to_do_if_Levenes_test_is_significant_in_a_mixed_ANOVA_in_SPSS

oneway alg_govt_acceptable_scale_bi country_recoded, tab

* There is a statistically significant difference between groups (although seemingly small compared to the differences within groups)

* Post hoc testing
pwmean alg_govt_acceptable_scale_bi, over(country_recoded) mcompare(tukey) effects

* This is ridiculous to interpret

*------------------------------------------------------------------------------*
* Replicating with simple ICC
*------------------------------------------------------------------------------*

*icc alg_govt_acceptable_scale_bi country_recoded
* THIS FAILS


*------------------------------------------------------------------------------*
* Basic OLS hierarchical model
*------------------------------------------------------------------------------*

*------------------------------------------------------*
* Full DV scale
*------------------------------------------------------*

* Options to consider:
* "noconstant" for the individual level, to suppress the constant term from the fixed-effect equation
* Use "vce(robust)" to cluster variances at the highest level of the multilevel model?


* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acceptable_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	subjective_income_rescaled ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	,  /// Level 2 options
	/// estmetric
	//

estat icc	

* When we add more fixed effects, the ICC for countries is still 2.3% (1.1% to 4.7%)

estimates store mixed_alg_gov_ac_bi_EPIS_a

*------------------------------------------------------*
* Efficiency subscale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acc_eff_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	subjective_income_rescaled ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	,  /// Level 2 options
	/// estmetric
	//

estimates store mixed_acc_eff_bi_EPIS_a

*------------------------------------------------------*
* Fairness subscale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acc_fair_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	subjective_income_rescaled ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	,  /// Level 2 options
	/// estmetric
	//

estimates store mixed_acc_fair_bi_EPIS_a


*------------------------------------------------------------------------------*
* OLS hierarchical model with country controls
*------------------------------------------------------------------------------*

* Options to consider:
* "noconstant" for the individual level, to suppress the constant term from the fixed-effect equation
* Use "vce(robust)" to cluster variances at the highest level of the multilevel model?

*------------------------------------------------------*
* Full DV scale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acceptable_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	subjective_income_rescaled ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	, /// Level 2 options
	///estmetric /// displays the variable names. Useful for specifying labels
	//
	
estat icc

estimates store mixed_alg_gov_ac_bi_EPIS_b

*------------------------------------------------------*
* Efficiency subscale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acc_eff_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	subjective_income_rescaled ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	, /// Level 2 options
	///estmetric /// displays the variable names. Useful for specifying labels
	//

estimates store mixed_acc_eff_bi_EPIS_b

*------------------------------------------------------*
* Fairness subscale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acc_fair_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	subjective_income_rescaled ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	, /// Level 2 options
	///estmetric /// displays the variable names. Useful for specifying labels
	//

estimates store mixed_acc_fair_bi_EPIS_b


*------------------------------------------------------------------------------*
* OLS hierarchical model with country controls, including leader approval
*------------------------------------------------------------------------------*

* Options to consider:
* "noconstant" for the individual level, to suppress the constant term from the fixed-effect equation
* Use "vce(robust)" to cluster variances at the highest level of the multilevel model?

*------------------------------------------------------*
* Full DV scale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acceptable_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	subjective_income_rescaled ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	leader_approval_rescaled ///
	, /// Level 2 options
	///estmetric /// displays the variable names. Useful for specifying labels
	//

estat icc	
	
estimates store mixed_alg_gov_ac_bi_EPIS_c

*------------------------------------------------------*
* Efficiency subscale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acc_eff_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	subjective_income_rescaled ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	leader_approval_rescaled ///
	, /// Level 2 options
	///estmetric /// displays the variable names. Useful for specifying labels
	//

estimates store mixed_acc_eff_bi_EPIS_c

*------------------------------------------------------*
* Fairness subscale
*------------------------------------------------------*

* Binary version
mixed ///
	/// Level 1: individual level
	/// DV
	alg_govt_acc_fair_scale_bi ///
	/// Demographics
	age_in_years_rescaled ///
	female ///
	subjective_income_rescaled ///
	education_cat_rescaled ///
	/// Political IVs
	lr_scale_rescaled ///
	populism_scale ///
	, /// Level 1 options
	|| /// Level 2: Country level
	country_recoded: /// The variable identifying the group structure at this level
	trust_in_others_wvs_rescaled ///
	un_e_government_index_rescaled ///
	digital_skills_index_rescaled ///
	leader_approval_rescaled ///
	, /// Level 2 options
	///estmetric /// displays the variable names. Useful for specifying labels
	//

estimates store mixed_acc_fair_bi_EPIS_c


********************************************************************************
* Exporting tables of these regressions
********************************************************************************

*---------------------------------------------------------------*
* Tables for use in presentations
*---------------------------------------------------------------*

esttab mixed_alg_gov_ac_bi_EPIS_a mixed_acc_eff_bi_EPIS_a mixed_acc_fair_bi_EPIS_a using "analysis\tables\EPIS/beamer\mixed_alg_gov_ac_bi_EPIS_a.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: basic hierarchical models, EPIS data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.4\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	///alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// Rescale the table so that it fits into a beamer frame
	/// Unfortunately this has to be after the caption for it to work properly, or I could just do this in the presentation file instead
	substitute( ///
	\begin{tabular*} \scalebox{0.44}{\begin{tabular*} ///
	\end{tabular*} \end{tabular*}} ///
	) ///
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(55)

esttab mixed_alg_gov_ac_bi_EPIS_b mixed_acc_eff_bi_EPIS_b mixed_acc_fair_bi_EPIS_b using "analysis\tables\EPIS/beamer\mixed_alg_gov_ac_bi_EPIS_b.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: hierarchical models with country controls, EPIS data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.4\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	///alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// Rescale the table so that it fits into a beamer frame
	/// Unfortunately this has to be after the caption for it to work properly, or I could just do this in the presentation file instead
	substitute( ///
	\begin{tabular*} \scalebox{0.44}{\begin{tabular*} ///
	\end{tabular*} \end{tabular*}} ///
	) ///
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country level trust in others (rescaled 0-1) (variance)" ///
		"UN E-Government index (rescaled 0-1) (variance)" ///
		"Digital skills index (rescaled 0-1) (variance)" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(55)	
	
esttab mixed_alg_gov_ac_bi_EPIS_c mixed_acc_eff_bi_EPIS_c mixed_acc_fair_bi_EPIS_c using "analysis\tables\EPIS/beamer\mixed_alg_gov_ac_bi_EPIS_c.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: hierarchical models with leader approval, EPIS data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.4\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	///alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// Rescale the table so that it fits into a beamer frame
	/// Unfortunately this has to be after the caption for it to work properly, or I could just do this in the presentation file instead
	substitute( ///
	\begin{tabular*} \scalebox{0.44}{\begin{tabular*} ///
	\end{tabular*} \end{tabular*}} ///
	) ///
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country level trust in others (rescaled 0-1) (variance)" ///
		"UN E-Government index (rescaled 0-1) (variance)" ///
		"Digital skills index (rescaled 0-1) (variance)" ///
		"Leader approval (rescaled 0-1 worst-best) (variance)" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(55)
	
*---------------------------------------------------------------*
* Tables for use in articles
*---------------------------------------------------------------*

esttab mixed_alg_gov_ac_bi_EPIS_a mixed_acc_eff_bi_EPIS_a mixed_acc_fair_bi_EPIS_a using "analysis\tables\EPIS/article\mixed_alg_gov_ac_bi_EPIS_a.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: basic hierarchical models, EPIS data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)

esttab mixed_alg_gov_ac_bi_EPIS_b mixed_acc_eff_bi_EPIS_b mixed_acc_fair_bi_EPIS_b using "analysis\tables\EPIS/article\mixed_alg_gov_ac_bi_EPIS_b.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: hierarchical models with country controls, EPIS data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country level trust in others (rescaled 0-1) (variance)" ///
		"UN E-Government index (rescaled 0-1) (variance)" ///
		"Digital skills index (rescaled 0-1) (variance)" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)	
	
esttab mixed_alg_gov_ac_bi_EPIS_c mixed_acc_eff_bi_EPIS_c mixed_acc_fair_bi_EPIS_c using "analysis\tables\EPIS/article\mixed_alg_gov_ac_bi_EPIS_c.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: hierarchical models with leader approval, EPIS data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	///page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country level trust in others (rescaled 0-1) (variance)" ///
		"UN E-Government index (rescaled 0-1) (variance)" ///
		"Digital skills index (rescaled 0-1) (variance)" ///
		"Leader approval (rescaled 0-1 worst-best) (variance)" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)
	
*---------------------------------------------------------------*
* Standalone tables
*---------------------------------------------------------------*

esttab mixed_alg_gov_ac_bi_EPIS_a mixed_acc_eff_bi_EPIS_a mixed_acc_fair_bi_EPIS_a using "analysis\tables\EPIS/standalone\mixed_alg_gov_ac_bi_EPIS_a.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: basic hierarchical models, EPIS data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)

esttab mixed_alg_gov_ac_bi_EPIS_b mixed_acc_eff_bi_EPIS_b mixed_acc_fair_bi_EPIS_b using "analysis\tables\EPIS/standalone\mixed_alg_gov_ac_bi_EPIS_b.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: hierarchical models with country controls, EPIS data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country level trust in others (rescaled 0-1) (variance)" ///
		"UN E-Government index (rescaled 0-1) (variance)" ///
		"Digital skills index (rescaled 0-1) (variance)" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)	
	
esttab mixed_alg_gov_ac_bi_EPIS_c mixed_acc_eff_bi_EPIS_c mixed_acc_fair_bi_EPIS_c using "analysis\tables\EPIS/standalone\mixed_alg_gov_ac_bi_EPIS_c.tex", replace ///
    b(3) se(3) /// values presented in the table
	nonumbers  noomitted ///
	nodepvars nobase ///
	label wrap ///
	/// eform /// this turns the coefficients into odds ratios
	title("OLS regressions of support for algorithmic governance: hierarchical models with leader approval, EPIS data") ///
	mtitles("Full DV scale" "Efficiency subscale" "Fairness subscale") ///
	/// LaTeX options to make the tables look better
	booktabs ///
	width(1.2\hsize) ///
	page(dcolumn) /// Not needed if this is to be called by another tex file
	alignment(D{.}{.}{-1}) /// This aligns the columns on the decimals, but Beamer doesn't like it
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	transform(ln*: exp(2*@) 2*exp(2*@)) ///
	eqlabels( ///
		"" ///
		"Country level trust in others (rescaled 0-1) (variance)" ///
		"UN E-Government index (rescaled 0-1) (variance)" ///
		"Digital skills index (rescaled 0-1) (variance)" ///
		"Leader approval (rescaled 0-1 worst-best) (variance)" ///
		"Country variance" ///
		"Residual variance", none) ///
	///varlabels(,elist(weight:_cons "{break}{hline @width}"))  ///
	varwidth(22)

	
********************************************************************************
* Plotting these results
********************************************************************************	

*------------------------------------------------------------------------------*
* Hierarchical logistic regression
*------------------------------------------------------------------------------*

*---------------------------------------------------------------*
* Basic models
*---------------------------------------------------------------*

*---------------------------------------------*
* Full DV scale
*---------------------------------------------*

coefplot ///
	(mixed_alg_gov_ac_bi_EPIS_a , label("Full DV scale") mcolor(edkblue) msymbol(circle) msize(vsmall) ciopts(lcolor(edkblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""basic hierarchical models", size(medsmall)) ///
	subtitle("Full DV scale""EPIS data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acceptable_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\EPIS/coefplots\coefplot-mixed-accept-EPIS_a_full.png", width(3300) height(2000) replace

*---------------------------------------------*
* Efficiency subscale
*---------------------------------------------*

coefplot ///
	(mixed_acc_eff_bi_EPIS_a , label("Efficiency subscale") mcolor(eltblue) msymbol(circle) msize(vsmall) ciopts(lcolor(eltblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""basic hierarchical models", size(medsmall)) ///
	subtitle("Efficiency subscale""EPIS data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		mixed_acc_eff_bi_EPIS_a:_cons = "Constant" ///
		lns1_1_1:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\EPIS/coefplots\coefplot-mixed-accept-EPIS_a_eff.png", width(3300) height(2000) replace	

*---------------------------------------------*
* Fairness subscale
*---------------------------------------------*

coefplot ///
	(mixed_acc_fair_bi_EPIS_a , label("Fairness subscale") mcolor(ebblue) msymbol(circle) msize(vsmall) ciopts(lcolor(ebblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""basic hierarchical models", size(medsmall)) ///
	subtitle("Fairness subscale""EPIS data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acc_fair_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\EPIS/coefplots\coefplot-mixed-accept-EPIS_a_fair.png", width(3300) height(2000) replace

*---------------------------------------------------------------*
* Hierarchical models with country level controls
*---------------------------------------------------------------*

*---------------------------------------------*
* Full DV scale
*---------------------------------------------*

coefplot ///
	(mixed_alg_gov_ac_bi_EPIS_b , label("Full DV scale") mcolor(edkblue) msymbol(circle) msize(vsmall) ciopts(lcolor(edkblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""hierarchical models with country level controls", size(medsmall)) ///
	subtitle("Full DV scale""EPIS data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acceptable_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country level trust in others (rescaled 0-1) (variance)" ///
		lns1_1_2:_cons = "UN E-Government index (rescaled 0-1) (variance)" ///
		lns1_1_3:_cons = "Digital skills index (rescaled 0-1) (variance)" ///
		lns1_1_4:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\EPIS/coefplots\coefplot-mixed-accept-EPIS_b_full.png", width(3300) height(2000) replace

*---------------------------------------------*
* Efficiency subscale
*---------------------------------------------*

coefplot ///
	(mixed_acc_eff_bi_EPIS_b , label("Efficiency subscale") mcolor(eltblue) msymbol(circle) msize(vsmall) ciopts(lcolor(eltblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""hierarchical models with country level controls", size(medsmall)) ///
	subtitle("Efficiency subscale""EPIS data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acc_eff_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country level trust in others (rescaled 0-1) (variance)" ///
		lns1_1_2:_cons = "UN E-Government index (rescaled 0-1) (variance)" ///
		lns1_1_3:_cons = "Digital skills index (rescaled 0-1) (variance)" ///
		lns1_1_4:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\EPIS/coefplots\coefplot-mixed-accept-EPIS_b_eff.png", width(3300) height(2000) replace	

*---------------------------------------------*
* Fairness subscale
*---------------------------------------------*

coefplot ///
	(mixed_acc_fair_bi_EPIS_b , label("Fairness subscale") mcolor(ebblue) msymbol(circle) msize(vsmall) ciopts(lcolor(ebblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""hierarchical models with country level controls", size(medsmall)) ///
	subtitle("Fairness subscale""EPIS data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acc_fair_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country level trust in others (rescaled 0-1) (variance)" ///
		lns1_1_2:_cons = "UN E-Government index (rescaled 0-1) (variance)" ///
		lns1_1_3:_cons = "Digital skills index (rescaled 0-1) (variance)" ///
		lns1_1_4:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\EPIS/coefplots\coefplot-mixed-accept-EPIS_b_fair.png", width(3300) height(2000) replace

*---------------------------------------------------------------*
* Model with country level controls, including leader approval
*---------------------------------------------------------------*

*---------------------------------------------*
* Full DV scale
*---------------------------------------------*

coefplot ///
	(mixed_alg_gov_ac_bi_EPIS_c , label("Full DV scale") mcolor(edkblue) msymbol(circle) msize(vsmall) ciopts(lcolor(edkblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""hierarchical models with leader approval", size(medsmall)) ///
	subtitle("Full DV scale""EPIS data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acceptable_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country level trust in others (rescaled 0-1) (variance)" ///
		lns1_1_2:_cons = "UN E-Government index (rescaled 0-1) (variance)" ///
		lns1_1_3:_cons = "Digital skills index (rescaled 0-1) (variance)" ///
		lns1_1_4:_cons = "Leader approval (rescaled 0-1 worst-best) (variance)" ///
		lns1_1_5:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\EPIS/coefplots\coefplot-mixed-accept-EPIS_c_full.png", width(3300) height(2000) replace

*---------------------------------------------*
* Efficiency subscale
*---------------------------------------------*

coefplot ///
	(mixed_acc_eff_bi_EPIS_c , label("Efficiency subscale") mcolor(eltblue) msymbol(circle) msize(vsmall) ciopts(lcolor(eltblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""hierarchical models with leader approval", size(medsmall)) ///
	subtitle("Efficiency subscale""EPIS data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acc_eff_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country level trust in others (rescaled 0-1) (variance)" ///
		lns1_1_2:_cons = "UN E-Government index (rescaled 0-1) (variance)" ///
		lns1_1_3:_cons = "Digital skills index (rescaled 0-1) (variance)" ///
		lns1_1_4:_cons = "Leader approval (rescaled 0-1 worst-best) (variance)" ///
		lns1_1_5:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\EPIS/coefplots\coefplot-mixed-accept-EPIS_c_eff.png", width(3300) height(2000) replace	

*---------------------------------------------*
* Fairness subscale
*---------------------------------------------*

coefplot ///
	(mixed_acc_fair_bi_EPIS_c , label("Fairness subscale") mcolor(ebblue) msymbol(circle) msize(vsmall) ciopts(lcolor(ebblue) lwidth(thin))) ///
	, xline(0) ci(95) ///
	xlabels(-.8(.2).8, labsize(vsmall)) ///
	title("OLS regressions of support for algorithmic governance:""hierarchical models with leader approval", size(medsmall)) ///
	subtitle("Fairness subscale""EPIS data", size(small)) ///
	/// Keep and transform the random-effects components
	keep(*:) /// Keep all of the equations
	/// "Variance parameters are returned by xtmixed as logarithms of standard deviations in e(b). To tabulate the parameters as standard deviations, back-transform them using the transform() option." http://repec.org/bocode/e/estout/advanced.html#advanced402
	/// I'm assuming that coefplot gets the variance parameters in the same way, and can verify it against the stata log's results
	transform(ln*: = exp(2*@) 2*exp(2*@) at*: = tanh(@)) ///
	eqlabels("{bf:Fixed effects}" "{bf:Random effects}" "{bf: }" "{bf: }" "{bf: }" "{bf: }" "{bf: }", asheadings) ///
	///eqlabels(none) 
	coeflabels( ///
		alg_govt_acc_fair_scale_bi:_cons = "Constant" ///
		lns1_1_1:_cons = "Country level trust in others (rescaled 0-1) (variance)" ///
		lns1_1_2:_cons = "UN E-Government index (rescaled 0-1) (variance)" ///
		lns1_1_3:_cons = "Digital skills index (rescaled 0-1) (variance)" ///
		lns1_1_4:_cons = "Leader approval (rescaled 0-1 worst-best) (variance)" ///
		lns1_1_5:_cons = "Country variance" ///
		lnsig_e:_cons = "Residual variance" ///
		, labsize(vsmall) wrap(36)) ///	
	graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) bgcolor(white)
	
graph export "analysis\graphs\EPIS/coefplots\coefplot-mixed-accept-EPIS_c_fair.png", width(3300) height(2000) replace
